using Microsoft.AspNetCore.Mvc;
using Vin.Extension.Framework.Aop;
using Vin.Extension.Framework.Base;
using Vin.Extension.Framework.Dto;
using Vin.Extension.Framework.Monitor.ServiceInterface;
using Vin.Tool.Attributes;

namespace Vin.Extension.Framework.Monitor.Controller.Controllers;

[Route("monitor/online")]
public class SysOnlineController : VinFrameworkBaseController
{
    [Inject] private readonly ISysOnlineService _sysOnlineService = null!;

    [VinAuthorize("monitor:online:list"), HttpGet("list")]
    public async Task<IActionResult> List([FromQuery] VinFrameworkBaseListDto dto)
    {
        return Success(await _sysOnlineService.ListAsync(dto), dto.TotalCount);
    }

    [VinAuthorize, HttpPost("heartbeat")]
    public async Task<IActionResult> Heartbeat()
    {
        return Success(await _sysOnlineService.HeartbeatAsync());
    }

    [VinAuthorize("monitor:online:force-logout"), HttpPost("force-logout")]
    public async Task<IActionResult> ForceLogout(string id, string? prefix = null)
    {
        return Success(await _sysOnlineService.ForceLogoutAsync(id, prefix));
    }
    
    [VinAuthorize, HttpPost("logout")]
    public async Task<IActionResult> Logout()
    {
        return Success(await _sysOnlineService.LogoutAsync());
    }
}